<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>数据库配置</title>
    <script type="text/javascript" src="js/jquery-1.8.3.min.js"></script>
    <link href="css/default.css" rel="stylesheet"/>

    <script type="text/javascript">
        $(document).ready(function(){
            $.ajax({
                url:"/get_dbconfig",
                type:"GET",
                contentType: "application/json; charset=utf-8",
                success:function(data){
                    $("#db_type").val(data.data.db_type);
                    $("#db_name").val(data.data.db_name);
                    $("#db_username").val(data.data.db_username);
                    $("#db_psd").val(data.data.db_psd);
                    $("#db_host").val(data.data.db_host);
                    $("#db_port").val(data.data.db_port);
                }
            })
        });
    </script>

    <script type="text/javascript">

        function test(){
            $.ajax({
                url:"/test_db",
                type:"GET",
                contentType: "application/json; charset=utf-8",
                success:function(){

                }
            });
        }

    </script>

    <script type="text/javascript">
        function save() {
            var db_type = $("#db_type").val();
            var db_name = $("#db_name").val();
            if (db_name == "") {
                alert("数据库名称不能为空")
            }
            var db_username = $("#db_username").val();
            if (db_username == "") {
                alert("用户名不能为空");
            }
            var db_psd = $("#db_psd").val();
            if (db_psd === "") {
                alert("密码不能为空");
            }
            var db_host = $("#db_host").val();
            if (db_host === "") {
                alert("HOST不能为空")
            }
            var db_port = $("#db_port").val();
            if (db_port == "") {
                alert("PORT不能为空")
            }
            $.ajax({
                url: '/save_dbconfig',
                type: "POST",
                contentType: "application/json; charset=utf-8",
                data: JSON.stringify({
                    "db_type": db_type,
                    "db_name": db_name,
                    "db_username": db_username,
                    "db_psd": db_psd,
                    "db_host": db_host,
                    "db_port": db_port
                }),
                success:function(data){
                    if(data.data){
                        alert("更新成功");
                    }else{
                        alert("更新失败");
                    }
                }
            })
        }
    </script>
</head>
<body>
<table class="Cam_table">
    <th colspan="6"> 数据库配置：</th>


    <tr>
        <td class="Td1">数据库类型类型：</td>
        <td>
            <select id="db_type">
                <option value="0">Sqlite</option>
                <option value="1">MySql</option>
                <option value="2">SqlServer</option>
            </select>
        </td>
    </tr>
    <tr>
        <td class="Td1">数据库名称：</td>
        <td><input id="db_name" type="text"/></td>
    </tr>
    <tr>
        <td class="Td1">用户名：</td>
        <td><input id="db_username" type="text"/></td>
    </tr>
    <tr>
        <td class="Td1">密码：</td>
        <td><input id="db_psd" type="text"/></td>
    </tr>
    <tr>
        <td class="Td1">HOST：</td>
        <td><input id="db_host" type="text"/></td>
    </tr>
    <tr>
        <td class="Td1">Port：</td>
        <td><input id="db_port" type="text"/></td>
    </tr>
    <tr style="text-align: center">
        <td colspan="6">
            <input class="button" type="button" name="update" onclick="save()" value="保存">
            <!--<input class="button" type="button" name="update" onclick="test()" value="测试连接">-->
        </td>
    </tr>

</table>
</body>
</html>